Completed
Push — master ( 4a55ed...a53e8c )
by Ajeh
26s
created

directives.js ➔ ???   B

Complexity

Conditions 1
Paths 16

Size

Total Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 16
dl 0
loc 81
rs 8.8076
nop 1

5 Functions

Rating   Name   Duplication   Size   Complexity  
A Directives.defineAlert 0 3 1
A directives.js ➔ Directives 0 5 1
A Directives.defineConfirm 0 69 1
A Directives.defineConfirm 0 11 2
B Directives.defineConfirm 0 46 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
// Directives
2
3
import {noop} from './utilities'
4
5
6
let Directives = function (Vue) {
7
    this.Vue = Vue
8
    this.confirmDefinition = this.defineConfirm()
9
    this.alertDefinition = this.defineAlert()
10
}
11
12
Directives.prototype.defineConfirm = function () {
13
    const _this = this
14
    const DirectiveDefinition = {}
15
16
    const clickHandler = function (event, el, binding) {
17
        event.preventDefault()
18
        event.stopImmediatePropagation()
19
20
        let confirmMessage = (function () {
21
            if (binding.value && binding.value.message) {
22
                return binding.value.message
23
            }
24
            return typeof binding.value === 'string' ? binding.value : null
25
        })()
26
27
        let thenCallback = (function () {
28
            if (binding.value && binding.value.ok) {
29
                return binding.value.ok
30
            } else {
31
                return () => {
32
                    el.removeEventListener('click', el.VuejsDialog.clickHandler, true)
33
34
                    _this.Vue.nextTick(() => {
35
                        (function (node) {
36
                            if (document.createEvent) {
37
                                let evt = document.createEvent('MouseEvents');
38
                                evt.initEvent('click', true, false);
39
                                node.dispatchEvent(evt);
40
                            } else if (document.createEventObject) {
41
                                node.fireEvent('onclick');
42
                            } else if (typeof node.onclick === 'function') {
43
                                node.onclick();
44
                            }
45
                        })(el)
46
47
                        el.addEventListener('click', el.VuejsDialog.clickHandler, true)
48
                    })
49
                }
50
            }
51
        })()
52
53
        let catchCallback = (function () {
54
            if (binding.value && binding.value.cancel) {
55
                return binding.value.cancel
56
            }
57
            return noop
58
        })()
59
60
        _this.Vue.dialog.confirm(confirmMessage).then(thenCallback).catch(catchCallback)
61
    }
62
63
    DirectiveDefinition.bind = (el, binding) => {
64
        if (el.VuejsDialog === undefined) {
65
            el.VuejsDialog = {}
66
        }
67
68
        el.VuejsDialog.clickHandler = function clickEventHandler(event) {
69
            clickHandler(event, el, binding)
70
        }
71
72
        el.addEventListener('click', el.VuejsDialog.clickHandler, true)
73
    }
74
75
    DirectiveDefinition.unbind = (el) => {
76
        el.removeEventListener('click', el.VuejsDialog.clickHandler, true)
77
    }
78
79
    return DirectiveDefinition
80
}
81
82
Directives.prototype.defineAlert = function () {
83
    //
84
}
85
86
export default Directives
87